package com.example.websocketdemo.controller.CIMVUE;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Iterator;
import java.util.Map;

@RestController
@RequestMapping("/VUEEmergencyLeftEmergencyPower")
public class EmergencyLeftEmergencyPowerController {
    @GetMapping("/data")
    public JSONArray a(HttpServletResponse response) throws IOException {
        response.setHeader("Access-Control-Allow-Origin", "*");
        JSONObject xinxi = new JSONObject();
        JSONObject xinxi1 = new JSONObject();
        JSONObject xinxi2 = new JSONObject();
        JSONObject xinxi3 = new JSONObject();

        JSONArray Array = new JSONArray();

        xinxi.put("title", "唐勇");
        xinxi.put("unit", "安保部");
        xinxi.put("phone", "13333000000");

        xinxi1.put("title", "郑磊");
        xinxi1.put("unit", "C班");
        xinxi1.put("phone", "13127559873");

        xinxi2.put("title", "杨小玲");
        xinxi2.put("unit", "上海石洞口煤气制气有限公司");
        xinxi2.put("phone", "13917964158");

        xinxi3.put("title", "徐明珍");
        xinxi3.put("unit", "C班");
        xinxi3.put("phone", "13816385005");

        Array.add(xinxi);
        Array.add(xinxi1);
        Array.add(xinxi2);
        Array.add(xinxi3);
        return Array;
    }



    private JSONArray bianli(JSONObject jsonObject){
        JSONArray jsonArray = new JSONArray();
//        JSONObject json = new JSONObject();
        Iterator iter = jsonObject.entrySet().iterator();
        while (iter.hasNext()) {
            JSONObject json = new JSONObject();
            Map.Entry entry = (Map.Entry) iter.next();
            json.put("title",entry.getKey().toString());
            json.put("value",entry.getValue().toString());
            jsonArray.add(json);
        }
        return jsonArray;
    }

//    private JSONArray bianli(JSONObject jsonObject) {
//        JSONArray jsonArray = new JSONArray();
//        JSONObject json = new JSONObject();
//        Iterator iter = jsonObject.entrySet().iterator();
//        while (iter.hasNext()) {
//            Map.Entry entry = (Map.Entry) iter.next();
//            if (entry.getKey().toString().equals("title")) {
//                json.put("title", entry.getKey().toString());
//            } else if (entry.getKey().toString().equals("phone")) {
//                json.put("phone", entry.getKey().toString());
//            } else if (entry.getKey().toString().equals("unit")) {
//                json.put("unit", entry.getValue().toString());
//            }
//            jsonArray.add(json);
//        }
//        return jsonArray;
//    }

}
